package com.yanggu.mapreduce.serializable;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/**
 * @version V1.0
 * @author: YangGu
 * @date: 2019/12/14 22:15
 * @description:
 */
public class FlowCountDriver {

    public static void main(String[] args) throws Exception {
        args = new String[2];
        args[0] = "input/serializable";
        args[1] = "output/serializable";


        //1. 得到job对象
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        //2. 设置关联driver、mapper、reducer类
        job.setJarByClass(FlowCountDriver.class);
        job.setMapperClass(FlowCountMapper.class);
        job.setReducerClass(FlowCountReducer.class);

        //3. 设置mapper输出类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(FlowBean.class);

        //4. 设置最终的输出类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(FlowBean.class);

        //设置分区的类
        //job.setPartitionerClass(CustomizePartitioner.class);

        //设置numberReduceTask
        //job.setNumReduceTasks(5);

        //5. 指定job的输入路径和输出路径
        FileInputFormat.setInputPaths(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        //6. 提交job。并结束程序
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }

}
